<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue</title>
  <script src="./js/vue.js"></script>
  <style>
    .active {
      color: red;
    }
  </style>
</head>

<body>
  <div id="app">
    <div>
      <span :class="{active:show[0]}" @click="tab(0)">新闻</span>
      <span :class="{active:show[1]}" @click="tab(1)">图片</span>
    </div>
    <div>
      <div v-if="show[0]">竞赛名单里，终于有了中国女演员的身影</div>
      <div v-if="show[1]">徐克想拍《神雕侠侣》，怎么就这么难？</div>
    </div>

  </div>

  <script>

    new Vue({
      el: '#app',
      data: {
        // tab切换多个选项，一般用数组
        show: [true, false]
      },
      methods: {
        tab(index) {
          // let show = new Array(this.show.length).fill(false)
          // show[index] = true
          this.show = this.show.map((item, idx) => idx == index ? true : false)
        }
      }
    })
  </script>
</body>

</html>